package com.snail.billing.data;

import java.util.UUID;

import android.text.TextUtils;

import com.snail.billing.util.BillingConfiguration;

public class UUIDManager {

	private static String uuid;
	
	public static void initUUID() {
		// UUID处理
		BillingConfiguration billingConfiguration = new BillingConfiguration();
		AccountFile accountFile = new AccountFile();
		String uuid = billingConfiguration.getUUID();
		if (TextUtils.isEmpty(uuid)) {
			uuid = accountFile.getUUID();
			if (TextUtils.isEmpty(uuid)) {
				uuid = createUUID();
				accountFile.setUUID(uuid);
			}
			billingConfiguration.setUUID(uuid);
		} else {
			accountFile.setUUID(uuid);
		}
		UUIDManager.uuid = uuid;
	}

	private static String createUUID() {
//		TelephonyManager telephonyManager = (TelephonyManager) MyEngine.getEngine().getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
//		String simSerial = telephonyManager.getSimSerialNumber();
//		if (!TextUtils.isEmpty(simSerial)) {
//			if (simSerial.length() > 10) {
//				return simSerial;
//			} else if (simSerial.length() > 3) {
//				return simSerial + telephonyManager.getDeviceId();
//			}
//		}
//		String phoneNumber = telephonyManager.getLine1Number();
//		if (!TextUtils.isEmpty(phoneNumber) && phoneNumber.length() >= 5) {
//			return phoneNumber;
//		}
		return UUID.randomUUID().toString();
	}

	public static String getUUID() {
		return uuid;
	}
}
